

package javaapplication6;
import java.awt.Frame;
import java.awt.*;
import javax.swing.*;
import java.awt.Dimension;
import javax.swing.JDialog;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JEditorPane;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

public class ProxySettings extends JDialog
{
  private JButton btnOk = new JButton();
  private JLabel jLabel1 = new JLabel();
  private JLabel jLabel2 = new JLabel();
  private JLabel jLabel3 = new JLabel();
  private JLabel jLabel4 = new JLabel();
  private JEditorPane proxyIp = new JEditorPane();
  private JEditorPane PortNum = new JEditorPane();
  private JEditorPane Usernam = new JEditorPane();
  private JEditorPane Passwor = new JEditorPane();
  private JCheckBox IsProxy = new JCheckBox();
public String getProxyIp(){

  return (proxyIp.getText()!="")?proxyIp.getText():"";

}
  public ProxySettings()
  {
    this(null, "", false);
  }

  public ProxySettings(Frame parent, String title, boolean modal)
  {
    super(parent, title, modal);
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }

  }

  private void jbInit() throws Exception
  {
    this.setSize(new Dimension(370, 140));
    this.getContentPane().setLayout(null);
    this.setModal(true);
    this.setTitle("Настройка прокси");
    btnOk.setText("Ok");

    btnOk.setBounds(new Rectangle(310, 100, 89, 27));

    btnOk.setActionCommand("Ok");
    btnOk.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          btnOk_actionPerformed(e);
        }
      });
    jLabel1.setText("прокси IP");
    jLabel1.setBounds(new Rectangle(30, 15, 43, 17));
    proxyIp.setText("168.192.11.1");
    proxyIp.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    jLabel2.setText("Номер порта");
    jLabel2.setBounds(new Rectangle(30, 45, 90, 15));
    PortNum.setText("8080");
    PortNum.setBounds(new Rectangle(125, 40, 45, 25));
    PortNum.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    jLabel3.setText("Имя пользвателя");
    jLabel3.setBounds(new Rectangle(185, 45, 90, 15));
    Usernam.setBounds(new Rectangle(280, 40, 100, 25));
    Usernam.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    jLabel4.setText("Пароль");
    jLabel4.setBounds(new Rectangle(405, 45, 90, 15));
    Passwor.setBounds(new Rectangle(485, 40, 100, 25));
    Passwor.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    IsProxy.setText("Использвать прокси");
    IsProxy.setBounds(new Rectangle(535, 40, 55, 25));
    IsProxy.setBorderPaintedFlat(true);
    IsProxy.setSelected(false);
    IsProxy.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          IsProxy_actionPerformed(e);
        }
      });
      
      this.getContentPane().setLayout(new BorderLayout());
      JPanel Panel1 = new JPanel();
      Panel1.add(jLabel1);
      Panel1.add(proxyIp);
      Panel1.add(jLabel2);
      Panel1.add(PortNum);
      JPanel Panel2 = new JPanel();
      Panel2.add(jLabel3);
      Panel2.add(Usernam);
      Panel2.add(jLabel4);
      Panel2.add(Passwor);
      JPanel Panel3 = new JPanel();
      Panel3.add(IsProxy);
      Panel3.add(btnOk);
      this.getContentPane().add(Panel1,BorderLayout.NORTH);
      this.getContentPane().add(Panel2,BorderLayout.CENTER);
      this.getContentPane().add(Panel3,BorderLayout.SOUTH);
    if(IsProxy.isSelected() == false)
      {
        Usernam.setEnabled(false);
        Passwor.setEnabled(false);
      }
      else
      if(IsProxy.isSelected() == true)
      {
        Usernam.setEnabled(true);
        Passwor.setEnabled(true);
      }
  }

  private void btnOk_actionPerformed(ActionEvent e)
  {
  this.hide();
  }

 public boolean getProx()
    { if(IsProxy.isSelected() == false)
         return false;
            else
                return true;
 }
  public String getPortNum()
  {
    return (PortNum.getText()!="")?PortNum.getText():"";
  }

  public String getPass()
  {
    return (Passwor.getText()!="")?Passwor.getText():"";
  }

  public String getUserName()
  {
    return (Usernam.getText()!="")?Usernam.getText():"";
  }

  private void IsProxy_actionPerformed(ActionEvent e)
  {
     if(IsProxy.isSelected() == false)
      {
        Usernam.setEnabled(false);
        Passwor.setEnabled(false);
      }
      else
      if(IsProxy.isSelected() == true)
      {
        Usernam.setEnabled(true);
        Passwor.setEnabled(true);
      }
  }
}